import Vue from 'vue'
import Router from 'vue-router'
import iView from 'iview'

// 空压系统的 router
// import air from './modules/air.js'
// 制冷系统的 router
import cooling from './modules/cooling.js'
// 智慧能源系统的 router
import console from './modules/console.js'
import system from './modules/system.js'

// 供电系统的 router
import electricity from './modules/electricity.js'

// 供水系统的 router
import water from './modules/water.js'

Vue.use(iView)
Vue.use(Router)
// 首页
const Main = () => import('../components/main/main.vue')
// 演示的 首页菜单 登录进入
const DisplayCardMenu = () => import('../components/main/DisplayCardMenu.vue')
// 三级路由 用于 二级的占位页
const PlacesHolder = () => import('../components/main/PlacesHolder.vue')
// 能源监控
const Carbon = () => import('../components/energy/Carbon.vue')
const Contrast = () => import('../components/energy/Contrast.vue')
// 能耗监测
const Hookup = () => import('../components/energyConsumption/hookup.vue')
const HookupNew = () => import('../components/energyConsumption/hookup_new.vue')
const EnergyDataRouter = () => import('../components/energyConsumption/EnergyDataRouter.vue')
// 后台配置
const Data = () => import('../components/configure/Data.vue')
const Icon = () => import('../components/configure/icon/Icon.vue')
const SysPic = () => import('../components/configure/SysPic.vue')
const Dict = () => import('../components/configure/Dict.vue')
// 登录
const Login = () => import('../components/login/Login.vue')
const NoFind = () => import('../components/NoFind.vue')
// 终端管理
const DeviceManage = () => import('../components/device/manage/DeviceManage.vue')
const DeviceType = () => import('../components/device/type/DeviceType.vue')
const BigDevice = () => import('../components/device/big_device/BigDevice.vue')
const DeviceConfig = () => import('../components/device/device_configuration/DeviceConfig.vue')
// 空间管理
const Space = () => import('../components/space/Space.vue')
// const StationSpace = () => import('../components/space/StationSpace.vue')
//  雷诺系统页面
const RenoutsSysImg = () => import('../components/energyConsumption/RenoutsSysImg.vue')
//  能源空间系统图维护数据页面
const EnergySpace = () => import('../components/space/EnergySpace.vue')
// base componets
const User = () => import('../components/base/User.vue')
const Menu = () => import('../components/base/Menu.vue')
const Role = () => import('../components/base/Role.vue')
const UserInfo = () => import('../components/base/UserInfo.vue')
// 报表
const DataForm = () => import('../components/form/DataForm.vue')
const DataCharts = () => import('../components/form/DataCharts.vue')
const Automation = () => import('../components/automation/Automation.vue')

const DataGas = () => import('../components/form/DataGas.vue')
const DataPowerSupply = () => import('../components/form/DataPowerSupply.vue')

const DataRefrigeration = () => import('../components/form/DataRefrigeration.vue')

const DataWaterSupply = () => import('../components/form/DataWaterSupply.vue')

// 能耗分析
const AllCarbon = () => import('../components/energy/AllCarbon.vue')
const EnergyAnalysis = () => import('../components/energy/EnergyAnalysis.vue')

const WaterMeter = () => import('../components/energy/WaterMeter.vue')
const ElectricMeter = () => import('../components/energy/ElectricMeter.vue')
const CoolingMeter = () => import('../components/energy/CoolingMeter.vue')
const GasMeter = () => import('../components/energy/GasMeter.vue')
const SteamMeter = () => import('../components/energy/SteamMeter.vue')
const AirMeter = () => import('../components/energy/AirMeter.vue')
const ReclaimedMeter = () => import('../components/energy/ReclaimedMeter.vue')
// 汇总成本
const costPool = () => import('../components/energy/costPool.vue')
// 汇总用水
const aggregateWater = () => import('../components/energy/aggregateWater.vue')
// 汇总用电
const aggregateElectricity = () => import('../components/energy/aggregateElectricity.vue')
// 汇总燃气
const aggregateGas = () => import('../components/energy/aggregateGas.vue')
// 汇总冷量
const aggregateCooling = () => import('../components/energy/aggregateCooling.vue')
// 汇总蒸汽
const summarySteam = () => import('../components/energy/summarySteam.vue')
// 汇总空气
const airCollections = () => import('../components/energy/airCollections.vue')
// 系统图区
const WaterSystemDisplay = () => import('../components/sysViews/WaterSystemDisplay.vue')

// 工艺监控 深色版 src/deep-views/tech-systems/TechMain.vue
const TechMain = () => import('../deep-views/tech-systems/TechMain.vue')
let router = new Router({
  mode: 'history',
  routes: [{
    path: '/',
    redirect: '/login' /* 默认路由 */
  }, {
    path: '/login',
    name: 'login',
    component: Login
  }, {
    path: '/userinfo',
    name: 'userinfo',
    component: UserInfo
  }, {
    path: '/display',
    name: 'display',
    component: DisplayCardMenu
  },
    {
      path: '/tech',
      component: Main,
      redirect: 'air/monitoring',
      children: [
        {
          path: '',
          component: RenoutsSysImg
        },
        {
          path: 'air',
          component: PlacesHolder,
          children: [
            {
              path: 'monitoring',
              component: RenoutsSysImg
            },
            {
              path: 'controllers',
              component: Automation
            },
            {
              path: 'charts',
              component: DataCharts
            },
            {
              path: 'forms',
              component: DataForm
            }
          ]
        }, {
          path: 'water',
          component: PlacesHolder,
          children: [
            {
              path: 'charts',
              component: DataWaterSupply
            }
          ]
        }, {
          path: 'gas',
          component: PlacesHolder,
          children: [
            {
              path: 'charts',
              component: DataGas
            }
          ]
        }, {
          path: 'power',
          component: PlacesHolder,
          children: [
            {
              path: 'charts',
              component: DataPowerSupply
            }
          ]
        }, {
          path: 'refrigeration',
          component: PlacesHolder,
          children: [
            {
              path: 'monitoring',
              component: WaterSystemDisplay
            },
            {
              path: 'charts',
              component: DataRefrigeration
            }
          ]
        }
      ]
    },
    {
      path: '/energy',
      component: Main,
      children: [
        {
          path: '',
          component: AllCarbon
        },
        {
          path: 'total',
          component: PlacesHolder,
          children: [
            {
              path: 'allcb',
              component: AllCarbon
            },
            {
              path: 'form',
              component: DataForm
            }
          ]
        },
        {
          path: 'totals',
          component: PlacesHolder,
          children: [
            {
              path: 'contrast',
              component: Contrast
            },
            {
              path: 'WaterMeter',
              component: WaterMeter
            },
            {
              path: 'ElectricMeter',
              component: ElectricMeter
            },
            {
              path: 'CoolingMeter',
              component: CoolingMeter
            },
            {
              path: 'GasMeter',
              component: GasMeter
            },
            {
              path: 'SteamMeter',
              component: SteamMeter
            },
            {
              path: 'AirMeter',
              component: AirMeter
            },
            {
              path: 'ReclaimedMeter',
              component: ReclaimedMeter
            },
            {
              path: 'bingo',
              component: EnergyDataRouter
            }
          ]
        },
        {
          path: 'analysis',
          component: PlacesHolder,
          children: [
            {
              path: 'energyal',
              component: EnergyAnalysis
            },
            {
              path: 'costPool',
              component: costPool
            },
            {
              path: 'aggregateWater',
              component: aggregateWater
            },
            {
              path: 'aggregateElectricity',
              component: aggregateElectricity
            },
            {
              path: 'summarySteam',
              component: summarySteam
            },
            {
              path: 'airCollections',
              component: airCollections
            },
            {
              path: 'aggregateCooling',
              component: aggregateCooling
            },
            {
              path: 'aggregateGas',
              component: aggregateGas
            },
            {
              path: 'contrast',
              component: Contrast
            }

          ]
        }
      ]
    },
    // {
    //   path: '/system',
    //   component: Main,
    //   children: [
    //     {
    //       path: '',
    //       component: DeviceType
    //     },
    //     {
    //       path: 'iot',
    //       component: PlacesHolder,
    //       children: [
    //         {
    //           path: 'deviceType',
    //           component: DeviceType
    //         }, {
    //           path: 'deviceManage',
    //           component: DeviceManage
    //         }, {
    //           path: 'configDevice',
    //           component: BigDevice
    //         },
    //         {
    //           path: 'bingo',
    //           component: EnergyDataRouter
    //         }
    //       ]
    //     },
    //     {
    //       path: 'air',
    //       component: PlacesHolder,
    //       children: [
    //         {
    //           path: 'monitoring',
    //           component: RenoutsSysImg
    //         },
    //         {
    //           path: 'controllers',
    //           component: Automation
    //         },
    //         {
    //           path: 'charts',
    //           component: DataCharts
    //         }
    //       ]
    //     },
    //     {
    //       path: 'space',
    //       component: PlacesHolder,
    //       children: [
    //         {
    //           path: 'space',
    //           component: Space
    //         },
    //         {
    //           path: 'stationSpace',
    //           component: StationSpace
    //         }
    //       ]
    //     },
    //     {
    //       path: 'config',
    //       component: PlacesHolder,
    //       children: [
    //         {
    //           path: 'icon',
    //           component: Icon
    //         }, {
    //           path: 'syspic',
    //           component: SysPic
    //         }, {
    //           path: 'espace',
    //           component: EnergySpace
    //         },
    //         {
    //           path: 'dict',
    //           component: Dict
    //         }
    //       ]
    //     },
    //     {
    //       path: 'hr',
    //       component: PlacesHolder,
    //       children: [
    //         {
    //           path: 'user',
    //           component: User
    //         },
    //         {
    //           path: 'menu',
    //           component: Menu
    //         },
    //         {
    //           path: 'role',
    //           component: Role
    //         }
    //       ]
    //     }
    //   ]
    // },
    {
      path: '/main',
      component: Main,
      children: [{
        path: 'air',
        component: PlacesHolder,
        children: [
          {
            path: 'monitoring',
            component: RenoutsSysImg
          },
          {
            path: 'controllers',
            component: Automation
          }
        ]
      }, {
        path: 'water',
        component: PlacesHolder,
        children: [
          {
            path: 'monitoring',
            component: WaterSystemDisplay
          }
        ]
      }, {
        path: 'gas',
        component: PlacesHolder,
        children: []
      }, {
        path: 'power',
        component: PlacesHolder,
        children: []
      }, {
        path: 'refrigeration',
        component: PlacesHolder,
        children: [
          {
            path: 'monitoring',
            component: WaterSystemDisplay
          }
        ]
      },
        {
          path: 'carbon',
          component: Carbon
        }, {
          path: 'contrast',
          component: Contrast
        }, {
          path: 'data',
          component: Data
        }, {
          path: 'icon',
          component: Icon
        }, {
          path: 'syspic',
          component: SysPic
        },
        {
          path: 'user',
          component: User
        },
        {
          path: 'summarySteam',
          component: summarySteam
        },
        {
          path: 'airCollections',
          component: airCollections
        },
        {
          path: 'aggregateCooling',
          component: aggregateCooling
        },
        {
          path: 'aggregateGas',
          component: aggregateGas
        },

        {
          path: 'allcb',
          component: AllCarbon
        },
        {
          path: 'energyal',
          component: EnergyAnalysis
        },
        {
          path: 'costPool',
          component: costPool
        },
        {
          path: 'aggregateWater',
          component: aggregateWater
        },
        {
          path: 'aggregateElectricity',
          component: aggregateElectricity
        },

        {
          path: 'charts',
          component: DataCharts
        },
        {
          path: 'DataGas',
          component: DataGas
        },
        {
          path: 'DataWaterSupply',
          component: DataWaterSupply
        },
        {
          path: 'DataRefrigeration',
          component: DataRefrigeration
        },
        {
          path: 'form',
          component: DataForm
        },
        {
          path: 'DataPowerSupply',
          component: DataPowerSupply
        },

        {
          path: 'menu',
          component: Menu
        },
        {
          path: 'role',
          component: Role
        },
        {
          path: 'auto',
          component: Automation
        },
        {
          path: 'dict',
          component: Dict
        }, {
          path: 'deviceManage',
          component: DeviceManage
        }, {
          path: 'deviceType',
          component: DeviceType
        }, {
          path: 'configDevice',
          component: BigDevice
        }, {
          path: 'devconfig',
          component: DeviceConfig
        }, {
          path: 'space',
          component: Space
        }, {
          path: 'espace',
          component: EnergySpace
        }, {
          path: 'airsys',
          component: RenoutsSysImg
        }, {
          path: 'hookup',
          component: Hookup
        },
        {
          path: 'bingo',
          component: EnergyDataRouter
        }, {
          path: 'hookupNew',
          component: HookupNew
        }]
    },
    // ...air,
    ...console,
    ...system,
    ...cooling,
    ...electricity,
    ...water,
    {
      path: '/tech-deep',
      name: 'tech-deep',
      component: TechMain,
      redirect: '/tech-deep/tech',
      children: [
        {
          path: '/tech-deep/tech',
          name: 'tech',
          component: RenoutsSysImg
        }
      ]
    }, {
      path: '/404',
      name: 'NoFind',
      component: NoFind
    }, {
      path: '*',
      name: 'other',
      redirect: '/404'
    }]
})
router.beforeEach((to, from, next) => {
  window.sourceData.forEach((source, index) => {
    source.cancel('取消请求')
  })
  window.sourceData = []
  // 加载进度条
  iView.LoadingBar.start()
  /* const nextRoute = ['account', 'order', 'course']
  const auth = store.state.auth
  // 跳转至上述3个页面
  if (nextRoute.indexOf(to.name) >= 0) {
    // 未登录
    if (!store.state.auth.IsLogin) {
      vueRouter.push({ name: 'login' })
    }
  }
  //已登录的情况再去登录页，跳转至首页
  if (to.name === 'login') {
    if (auth.IsLogin) {
      vueRouter.push({ name: 'home' })
    }
  } */
  if (to.path.indexOf('home') > -1) {
    let IsLogin = true
    if (IsLogin) {
      next()
    } else {
      next({path: '/login'})
    }
  }
  next()
})
router.afterEach(route => {
  // 加载进度条
  iView.LoadingBar.finish()
})
export default router
